var PepSim = {};

PepSim.rand = function (max) {
	return Math.floor( Math.random() * max );
};

PepSim.ns = function (name) {
	var parent = window,
		parts = name.split('.'),
		i;
		
	for (i = 0; i < parts.length ; i = i + 1) {
		if (!parent[parts[i]]) {
			parent[parts[i]] = {};
		}
		parent = parent[parts[i]];
	}
	return parent;
};

PepSim.define = function (name, config) {
	var parent = window,
		parts = name.split('.'),
		i, ctor;
		
	for (i = 0; i < parts.length - 1; i = i + 1) {
		if (!parent[parts[i]]) {
			parent[parts[i]] = {};
		}
		parent = parent[parts[i]];
	}

	ctor = function () {
		if (this.init) {
			this.init.apply(this, arguments);
		}
	};
	ctor.prototype = config;
	parent[parts[parts.length - 1]] = ctor;
	
	return ctor;
};